package com.stackexchange.webapis.methodgroups
{
	import com.stackexchange.webapis.client.StackExchangeService;
	import com.stackexchange.webapis.events.StackExchangeResultEvent;
	
	import flash.events.Event;
	import flash.net.URLLoader;
	
	/**
	 * Broadcast as a result of the getComments method being called
	 *
	 * The event contains the following properties
	 *	success	- Boolean indicating if the call was successful or not
	 *	data - When success is true, contains a "comments" CommentList instance
	 *		   When success is false, contains an "error" StackExchangeError instance
	 *
	 * @see com.producteev.webapis.StackExchangeError
	 */
	[Event(name="postsGetComments", type="com.stackexchange.webapis.events.StackExchangeResultEvent")]
	
	public class Posts extends AbstractMethod
	{
		private static const GET_COMMENTS:String = "{id}/comments";
		
		public function Posts(service:StackExchangeService, methodCaller:MethodCaller, responseParser:ResponseParser)
		{
			super(service, methodCaller, responseParser);
		}
		
		/**
		 * Gets the comments associated with a set of posts (questions and/or answers).  
		 *
		 * @param id A single primary key identifier or an array of identifiers
		 * @param params a list of params
		 * 
		 * @see http://api.stackoverflow.com/1.0/help/method?method=posts/{id}/comments
		 */
		public function getComments(ids:Array, params:Object=null):void
		{
			call(GET_COMMENTS, getCommentsHandler, {id:ids}, params);
		}
		
		private function getCommentsHandler(event:Event):void
		{
			processAndDispatch(URLLoader(event.target).data,
				StackExchangeResultEvent.POSTS_GET_COMMENTS,
				_responseParser.parseComments);
		}
	}
}